import { message } from "antd";
import apis from "./templateCenterApi";

const { msgTemplateQuery } = apis;

export default {
  namespace: "templateCenter",
  state: {},
  effects: {
    *msgTemplateQuery({ payload = {} }, { call, put }) {
      const { data, errCode, errMsg, totalCount, totalPage } = yield call(
        msgTemplateQuery,
        payload
      );
      if (errCode === 0) {
        yield put({
          type: "getModels",
          payload: { data, totalCount, totalPage }
        });
      } else {
        message.error(errMsg);
      }
    }
  },
  reducers: {
    getModels: (state, { payload }) => ({
      ...state,
      modelList: payload.data,
      totalCount: payload.totalCount,
      totalPage: payload.totalPage
    })
  }
};
